<?php

namespace app\common\model;

use think\Model;

/**
 * 审批流
 */
class ApprovesFlow extends Model
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 追加属性
    protected $append = [
        'type_text',
        'createtime_text',
    ];

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    //审批类型:1=请假,2=报销,3=采购
    public function getTypeListName()
    {
        return [
            '1'        => '请假审批',
            '2'        => '报销审批',
            '3'        => '采购审批',
        ];
    }

    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        return !$value ? '' :$this->getTypeListName()[$value];
    }

    //获取列表
    public static function getLists()
    {
        return self::where('status','normal')->order('createtime desc')->select();
    }

    //获取指定类型的列表
    public static function getTypeLists($type)
    {
        return self::where('status','normal')->where('type',$type)->order('createtime desc')->select();
    }


}
